package com.spc.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.spc.constant.MessageConstant;
import com.spc.entity.PageResult;
import com.spc.entity.Result;
import com.spc.service.SportService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sport")
public class SportController {


    @Reference
    private SportService sportService;


    @RequestMapping("/add")
    public Result addIllness(@RequestBody Map map){


        try {

            sportService.add(map);

        }catch (Exception e){

            return new Result(false, MessageConstant.ADD_Illness_FAIL);

        }


        return new Result(true,MessageConstant.ADD_Illness_SUCCESS);

    }
    /**
     * 查询分页疾病项
     */
    @RequestMapping("/findPage")
    public PageResult findAll(@RequestBody Map map){

        PageResult pageResult = null;

        try {
            pageResult =  sportService.findPage(map);

            return  pageResult;
        }catch (Exception e){

            e.printStackTrace();

            return pageResult;

        }





    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            Map map = sportService.findById(id);
            return new Result(true,MessageConstant.QUERY_Illness_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            //说明服务调用失败
            return new Result(false,MessageConstant.QUERY_Illness_FAIL);
        }
    }


    //编辑检查项
    @RequestMapping("/edit")
    public Result edit(@RequestBody Map map,Integer id){
        try {
            sportService.edit(map,id);
        } catch (Exception e) {
            e.printStackTrace();
            //说明服务调用失败
            return new Result(false, MessageConstant.EDIT_Illness_FAIL);
        }

        return new Result(true, MessageConstant.EDIT_Illness_SUCCESS);
    }


    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        try {
            sportService.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
            //说明服务调用失败
            return new Result(false, MessageConstant.DELETE_Illness_FAIL);
        }

        return new Result(true, MessageConstant.DELETE_Illness_SUCCESS);


    }

    //添加科室
    @RequestMapping("/addDepartments")
    public Result addDepartments(@RequestBody Map map){

        try {

            sportService.addDepartments(map);

        }catch (Exception e){

            return new Result(false, MessageConstant.ADD_DEPARTMENT_FAIL);

        }


        return new Result(true,MessageConstant.ADD_DEPARTMENT_SUCCESS);



    }

    //回显科室
    @RequestMapping("/findAllDepartments")
    public Result findAllDepartments(){

        try {

            List<Map> list = sportService.findAllDepartments();
            return new Result(true,MessageConstant.QUERY_Illness_SUCCESS,list);
        }catch (Exception e){

            return new Result(false, MessageConstant.QUERY_Illness_FAIL);

        }






    }




}
